<template>
  <view class="result-container">
    <!-- 风险等级 -->
    <view class="card risk-card">
      <text class="card-title">风险等级</text>
      <text class="risk-level" :class="riskLevelClass">{{ result.risk_level }}</text>
      <text class="risk-description">{{ result.summary.totalScoreDescription }}</text>
    </view>

    <!-- 总均分 -->
    <view class="card score-card">
      <text class="card-title">总均分</text>
      <text class="total-score">{{ result.total_score }}</text>
    </view>

    <!-- 各维度得分 -->
    <view class="card dimension-card">
      <text class="card-title">各维度得分</text>
      <view class="dimension-list">
        <view class="dimension-item" v-for="factor in result.factors" :key="factor.name">
          <text class="dimension-name">{{ factor.name }}</text>
          <view class="progress-bar">
            <view class="progress" :style="{ width: getProgressWidth(factor.averageScore) }"></view>
          </view>
          <text class="dimension-score">{{ factor.averageScore }}</text>
          <text class="dimension-description">{{ factor.description }}</text>
        </view>
      </view>
    </view>
	<!-- ai分析结果 -->
	
	<view class="card">
		  <text class="card-title">ai分析结果</text>
		  <text class="ai-estimation">{{result.ai_estimation}}</text>
	</view>
	
    <!-- 记录时间 -->
    <view class="card time-card">
      <text class="card-title">记录时间</text>
      <text class="record-time">{{ formattedDate }}</text>
    </view>
  </view>
</template>

<script>
export default {
  props: ["result"],
  computed: {
    riskLevelClass() {
      switch (this.result.risk_level) {
        case "低风险": return "low-risk";
        case "中风险": return "medium-risk";
        case "高风险": return "high-risk";
        default: return "";
      }
    },
    // 格式化 created_at 日期
    formattedDate() {
      if (!this.result.created_at) return "无数据";
      const date = new Date(this.result.created_at);
      return date.toLocaleString(); // 转换为本地时间格式
    }
  },
  methods: {
    getProgressWidth(score) {
      return `${(score / 4) * 100}%`;
    }
  }
};
</script>

<style scoped>
/* 整体布局 */
.result-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
}

/* 卡片样式 */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 标题 */
.card-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
}

/* 风险等级样式 */
.risk-level {
  font-size: 20px;
  font-weight: bold;
  padding: 8px 12px;
  border-radius: 8px;
  display: inline-block;
  text-align: center;
}

/* 不同风险等级的颜色 */
.low-risk {
  color: #1e8e3e;
  background: #e6f7ea;
}

.medium-risk {
  color: #d97706;
  background: #fff3cd;
}

.high-risk {
  color: #d32f2f;
  background: #fdecea;
}

/* 总均分样式 */
.total-score {
  font-size: 24px;
  font-weight: bold;
  color: #0056b3;
  text-align: center;
}

/* 维度得分 */
.dimension-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dimension-item {
  display: flex;
  flex-direction: column;
  background: #f9f9f9;
  border-radius: 8px;
  padding: 12px;
  gap: 6px;
}

/* 维度名 */
.dimension-name {
  font-weight: bold;
  font-size: 16px;
  color: #333;
}

/* 进度条容器 */
.progress-bar {
  width: 100%;
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
}

/* 进度条填充 */
.progress {
  height: 100%;
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  transition: width 0.3s ease-in-out;
}

/* 维度得分 */
.dimension-score {
  font-size: 16px;
  font-weight: bold;
  color: #007bff;
}

/* 维度描述 */
.dimension-description {
  font-size: 14px;
  color: #666;
}

/* 记录时间样式 */
.record-time {
  font-size: 14px;
  color: #555;
  margin-top: 5px;
}
</style>
